import 'dart:async';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:chatgreat/helper/constant.dart';
import 'package:chatgreat/helper/image.dart';
import 'package:chatgreat/helper/my_widget.dart';
import 'package:chatgreat/page/component/image.dart';
import 'package:chatgreat/page/component/random_avatar.dart';
import 'package:chatgreat/page/component/theme/custom_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ImageCard extends StatelessWidget {
  final String image;
  final String? username;
  final int? userId;
  final int? likeNum;
  final bool enableDelete;
  final Function()? onTap;
  final Function()? onDeleteTap;
  const ImageCard({
    super.key,
    required this.image,
    required this.enableDelete,
    this.username,
    this.userId,
    this.likeNum,
    this.onTap,
    this.onDeleteTap,
  });


  @override
  Widget build(BuildContext context) {
    final customColors = Theme.of(context).extension<CustomColors>()!;
    return InkWell(
      onTap: onTap,
      child: Stack(
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(11),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                image.isEmpty
                    ? Column(
                      children: [
                        const SizedBox(height: 11),
                        LinearProgressIndicator(color: customColors.themeBlueColor,minHeight: 5, borderRadius: BorderRadius.circular(2.5),),
                        const SizedBox(height: 4),
                        MyTextWeight('正在生成中...', 14, Colors.grey, FontWeight.w400),
                      ],
                    )
                    : CachedNetworkImage(
                      imageUrl: image,
                      // placeholder: (context, url) => Center(child: CircularProgressIndicator(color: customColors.themeBlueColor)),
                      fit: BoxFit.cover,
                ),

              ],
            ),
          ),

          if (image.isNotEmpty)
            Positioned(
            bottom: 9.w,
            left: 12.w,
            child: Row(
              children: [
                imgWidget(14, 13.5, 'draw_zan'),
                const SizedBox(width: 5),
                Padding(
                  padding: const EdgeInsets.only(top: 2),
                  child: MyTextWeight('$likeNum', 13, Colors.white, FontWeight.normal),
                )
              ],
            ),
          ),
          if (image.isNotEmpty)
            Positioned(
            bottom: 0,
            right: 0,
            child: Visibility(
              visible: enableDelete,
              child: InkWell(
                child: imgWidget(64, 64, 'draw_shanchu'),
                onTap: onDeleteTap,
              ),
            ),
          )
        ],
      ),
    );
  }
}
